﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ToolSheetDeptList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            //if (Membership.GetUser() != null)
            //{
            //    string strUserName = Membership.GetUser().ToString();

            //    SqlConnection objConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["smsConnectionString"].ConnectionString);

            //    DataSet ds = new DataSet();
            //    SqlDataAdapter da = new SqlDataAdapter("select ToolSheet.ToolSheetID, aspnet_Users.UserName,ConstructionCorp,ProposeDate,StartDate,FinishDate from ToolSheet, aspnet_Users  where ToolSheet.ProposerID = aspnet_Users.UserId", objConnection);
            //    da.Fill(ds, "StaffinfoRole");
            //    DataTable dt1 = ds.Tables["StaffinfoRole"];


            //    SqlCommand objCommand = new SqlCommand("Users_FindDepartmentId", objConnection);
            //    objCommand.CommandType = CommandType.StoredProcedure;

            //    SqlParameter objParameter = new SqlParameter("@UserName", SqlDbType.NVarChar);
            //    objCommand.Parameters.Add(objParameter);
            //    objParameter.Direction = ParameterDirection.Input;
            //    objParameter.Value = strUserName;

            //    SqlParameter objOutputParameter = new SqlParameter("@DepartmentID", SqlDbType.Int);
            //    objCommand.Parameters.Add(objOutputParameter);
            //    objOutputParameter.Direction = ParameterDirection.Output;

            //    objConnection.Open();

            //    objCommand.ExecuteNonQuery();
            //    Session["UserDepartmentID"] = (Int32)objOutputParameter.Value;

            //    ArrayList al = new ArrayList();
            //    for (int i = 0; i < dt1.Rows.Count; i++)
            //        al.Add(dt1.Rows[i].ItemArray[0]);

            //    Session["Role"] = al;
            //    Session["UserName"] = strUserName;
            //}
        
        SetData();
        }

    }

    public void SetData()
    {
        ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings["smsConnectionString"];
        string connectionString = connObj.ConnectionString;
        SqlConnection objConnection = new SqlConnection(connectionString);

        String query = "select ToolSheet.ToolSheetID, aspnet_Users.UserName AS 申请人 ,ConstructionCorp AS 施工单位,Convert(char(10),ProposeDate,121) AS 申请日期,Convert(char(10),StartDate,121) AS 开始日期,Convert(char(10),FinishDate,121) AS 结束日期"+
                        " from ToolSheet, aspnet_Users where ToolSheet.ProposerID = aspnet_Users.UserId"+
                         " and ToolSheet.DeptAuditStatus = '待批'";// and staffInfo.DepartmentID = " + Session["UserDepartmentID"].ToString;

        SqlDataAdapter da = new SqlDataAdapter(query, objConnection);

        DataSet ds = new DataSet();
        da.Fill(ds, "工具单申请");
        DataTable dt = ds.Tables["工具单申请"];
        DataView view = new DataView(dt);

        this.UltraWebGrid1.DataSource = view;
        this.UltraWebGrid1.DataKeyField = "ToolSheetID";
        this.UltraWebGrid1.DataBind();
        this.UltraWebGrid1.Columns[1].Hidden = true;

    }

    public static string GetNavigateUrl(Object item1)
    {
        String strToolSheetID = (String)System.Web.UI.DataBinder.Eval(item1, "ToolSheetID");

        String result = "~/ToolSheetDeptAudit.aspx?ToolSheetID=";
        result += strToolSheetID;
        return result;
    }


}
